package com.woniuxy.depot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.depot.model.DTO.Condition;
import com.woniuxy.depot.model.DTO.OutStockDTO;
import com.woniuxy.depot.model.DTO.Statistics;
import com.woniuxy.depot.model.VO.StockGoodsVO;
import com.woniuxy.depot.model.VO.StockGoodssVO;
import com.woniuxy.depot.model.entity.DepotOutStock;
import com.woniuxy.depot.service.DepotOutStockService;
import com.woniuxy.response.ResponseResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/outStock")
public class DepotOutStockController {
    @Resource
    private DepotOutStockService outStockService;
    @GetMapping("/all/{current}/{size}")
    public ResponseResult<Page<DepotOutStock>> all(@PathVariable int current,@PathVariable int size){

        return new ResponseResult<>(ResponseResult.SUCCESS,"success",outStockService.all(current,size));
    }

    @GetMapping("/searchByGoodsCode")
    public ResponseResult<List<DepotOutStock>> searchByGoodsCode(@RequestParam String code){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",outStockService.searchByGoodsCode(code));
    }

    @PostMapping("/searchByCondition")
    public ResponseResult<List<DepotOutStock>> searchByCondition(@RequestBody Condition condition) {
        System.out.println(condition);
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",outStockService.searchByCondition(condition));
    }
    @PreAuthorize("hasAuthority('depot:agreeOut')")
    @PutMapping("/updateState/{formNo}/{state}")
    public ResponseResult<Boolean> updateState(@PathVariable String formNo,@PathVariable Integer state){

        return new ResponseResult<>(ResponseResult.SUCCESS,"success",outStockService.updateState(formNo,state));
    }

    @PreAuthorize("hasAuthority('depot:addOut')")
    @PostMapping("/insert")
    public ResponseResult<Boolean> insert(@RequestBody OutStockDTO outStockDTO){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",outStockService.insert(outStockDTO));
    }

    @GetMapping("/detail/{id}")
    public ResponseResult<List<StockGoodssVO>> detail(@PathVariable Integer id){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",outStockService.detail(id));
    }

    @GetMapping("/statistics")
    public ResponseResult<List<Statistics>> statistics(){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",outStockService.statistics());
    }
}
